package com.kindergarten.controller;

import com.kindergarten.pojo.Page;
import com.kindergarten.pojo.Role;
import com.kindergarten.service.IPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class LoginController {

    @Autowired
    IPageService pageService;

    /**
     * 跳转登录页面
     * @return
     */
    @RequestMapping({"/", "/login.html"})
    public String toLoginHtml() {
        return "login";
    }

    /**
     * 跳转内部首页
     * @return
     */
    @RequestMapping(value = "/index.html")
    public String toIndexHtml(Model model, HttpSession session) {
        //查询当前登录人的角色对应的菜单集合
        Role role = (Role) session.getAttribute("role");
        //角色ID
        Integer roleId = role.getRoleId();
        List<Page> pageList = pageService.findMyMenus(roleId.toString());
        model.addAttribute("pageList",pageList);
        return "index";
    }

}
